﻿<%@ LANGUAGE="JavaScript" codepage=65001%><?xml version="1.0" encoding="UTF-8"?>
<!-- #include file="AAC.asp" -->
<!-- #include file="Config.asp" -->
<%
//==================================
//  Weather for google earth v1.0
//  更新时间: 2007-08-24
//  embont@gmail.com
//  www.dnxh.cn
//==================================


Server.ScriptTimeOut = 999;
Response.ContentType = "text/xml";//
Response.CharSet = 65001 ;//[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]

var alt  = Request.QueryString("CAMERA");
var BBOX = Request.QueryString("BBOX");
var _ary = String(BBOX).split(",");
var west    = _ary[0];
var south   = _ary[1];
var east    = _ary[2];
var north   = _ary[3];

var XMLs = [];
var updataOK = true;
var curren = true;


var nowdate = new Date();
var nowyear = nowdate.getYear();
var nowday  = nowdate.getDate();
var nowhour = nowdate.getHours();
var fso = Server.CreateObject("Scripting.FileSystemObject");

//补位
function timetwo(U){
var a=new String(U);
  if(a.length==1){
  a="0"+new String(U);
  }
  return(a);
  }
//判断奇数偶数
function Is_odd(n){
 var a = n%2;
 var b;
 if(a==1){ b=true;}else{b=false};
 return(b);
}
//获得XML格式时间YYYY-MM-DD
function XMLtime(n){
   var nowdate = new Date();
   var t = nowdate.getTime()+n*60*60*1000*12;
   var c = new Date(t);
   var d = c.getYear()+"-"+timetwo(c.getMonth()+1)+"-"+timetwo(c.getDate());
   return(d);
}
//获得XML内的各个参数
function XMLparse(XMLn,DAYn,ND){
var day = XMLs[XMLn].getElementsByTagName("day")[DAYn];
this.dnam = XMLs[XMLn].getElementsByTagName("dnam")[0].text;
this.lat = XMLs[XMLn].getElementsByTagName("lat")[0].text;
this.lon = XMLs[XMLn].getElementsByTagName("lon")[0].text;
this.hi = day.getElementsByTagName("hi")[0].text;
this.low = day.getElementsByTagName("low")[0].text;
this.icon = day.getElementsByTagName("icon")[ND].text;
this.winds = day.getElementsByTagName("s")[ND].text;
}
%>
<%
//////////建立当前屏幕字符集
var vSQL;
	if (alt>4000000){
	//取最高级别的点
	vSQL = "gew WHERE lon>"+west+"AND lon<"+east+"AND lat>"+south+"AND lat<"+north+"AND scale<2";
	}else 
	//取省级以上点
	if (alt<=4000000 && alt>1000000){
	vSQL = "gew WHERE lon>"+west+"AND lon<"+east+"AND lat>"+south+"AND lat<"+north+"AND scale<3";
	}else{
	//取全部点
	vSQL = "gew WHERE lon>"+west+"AND lon<"+east+"AND lat>"+south+"AND lat<"+north;
	}
	var oAAC = new AAC(mdbfile,vSQL);
	oAAC.open(3,1);
	var oRS = oAAC.oRecordSet;
//////////构成XML列队
if (oRS.RecordCount == 0){
		//清除前一个当前屏幕的记录集
	    oRS = "";
	    oAAC.close();
	    oAAC = "";
		//新建一个记录集，用来筛选最近点。		
		var vAAC = new AAC(mdbfile,"gew");
		vAAC.open(3,1);
		var vRS = vAAC.oRecordSet;
        // 取得窗口中心点坐标位置
	    var Latitude  = (Number(south)+Number(north))/2;
	    var Longitude = (Number(west) +Number(east) )/2;
		//最近点计算c*c=a*a+b*b
		var n = 0;
		var c = new Array();
				
		for(vRS.MoveLast();!vRS.BOF;vRS.MovePrevious()){
		n++;
		var vlon = vRS("lon");
		var vlat = vRS("lat");
		var ven = vRS("en");
		var vcn = vRS("cn");
		//计算最近距离
		var a   = Latitude - vlat;
		    a   = Math.abs(a)
		var b   = Longitude- vlon;
		    b   = Math.abs(b)		
		var c2  = a*a+b*b ;
		c.push(Math.sqrt(c2) + "|" + vRS("code")+ "|" + vcn + "|" + ven);
		}
		c.sort();
		var vcodes = c[0];
		var vcode  = vcodes.split("|");
		var code   = vcode[1];
		var cn = vcode[2]+"";
		if(cn=="undefined"||cn=="null"){
		cn=vcode[3];
		}
        if(fso.FileExists(Server.MapPath("xml/"+code+".xml"))){
	        //======Load XML=========================
	        var XML = Server.CreateObject("Microsoft.XMLDOM");
	        XML.async = false;
	        XML.load(Server.MapPath("xml/"+code+".xml"));
	        XML.getElementsByTagName("dnam")[0].firstChild.nodeValue = cn;
	        XMLs.push(XML);
        }
        curren=false;
	    vRS = "";
	    vAAC.close();
	    vAAC = "";
}else{
	    for(oRS.MoveLast();!oRS.BOF;oRS.MovePrevious()){
        var code = oRS("code");
        var cn = oRS("cn")+"";
        if(cn=="undefined"||cn=="null"){cn=oRS("en")}
        if(fso.FileExists(Server.MapPath("xml/"+code+".xml"))){
	        //======Load XML=========================
	        var XML = Server.CreateObject("Microsoft.XMLDOM");
	        XML.async = false;
	        XML.load(Server.MapPath("xml/"+code+".xml"));
	        XML.getElementsByTagName("dnam")[0].firstChild.nodeValue = cn;
	        XMLs.push(XML);
	        XML='';
	        }
        }
	    oRS = "";
	    oAAC.close();
	    oAAC = "";
}
%><kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<%
if(XMLs.length!=0){
for(var i=1;i<21;i++){
   //晚上
   if(!Is_odd(i)){%>
	<Folder>
        <name><%=XMLtime(i-2)%>-晚上</name>
		<TimeSpan>
			<begin><%=XMLtime(i-2)%>T19:00:01Z</begin>
			<end><%=XMLtime(i)%>T07:00:00Z</end>
		</TimeSpan>
		<%
		var vXML;
		if(curren){
		for(var n=0;n<XMLs.length;n++){
		vXML = new XMLparse(n,i/2-1,1);
		%>
        <Placemark>
        <name><%=vXML.dnam%>(<%=vXML.low%>℃~<%=vXML.hi%>℃)</name>
		<Snippet maxLines="2"/>
        <description><![CDATA[风速：<%=vXML.winds%>千米/每小时]]></description>
        <Style>
			<IconStyle>
				<scale>1.2</scale>
				<Icon>
					<href><%=ServerURL%>/img/icon/<%=vXML.icon%>s.png</href>
				</Icon>
			</IconStyle>
            <BalloonStyle>
				<color>FFCC99</color>
				<text><![CDATA[<img src="<%=ServerURL%>/img/logo/logo-ge.png" width="121" height="30" border="0" /><br /><b><font face="宋体" size="5" color="#000000">$[name]</font></b><br /><font face="宋体" size="4" color="#000000">$[description]</font><br /><font face="Verdana" size="3">Design©<a href="http://www.dnxh.cn">www.dnxh.cn</a> || Date©<a href="http://www.weather.com/?prod=xoap&amp;par=1017780104">Weather.com</a><sup>®</sup> || Icon©<a href="http://www.yahoo.com">Yahoo</a></font>]]></text>
			</BalloonStyle>
		</Style>
			<Point>
				<coordinates><%=vXML.lon%>,<%=vXML.lat%></coordinates>
			</Point>
        </Placemark>
        <%}}else{
        vXML = new XMLparse(0,i/2-1,1);
        %>
    <ScreenOverlay>
    <name><%=vXML.dnam%>(<%=vXML.low%>℃~<%=vXML.hi%>℃)</name>
    <description><![CDATA[风速：<%=vXML.winds%>千米/每小时]]></description>
    <drawOrder>80</drawOrder>
    <Icon>
      <href><![CDATA[<%=ServerURL%>/img/icon/<%=vXML.icon%>n.png]]></href>
    </Icon>
    <overlayXY x="0" y="180" xunits="fraction" yunits="pixels"/>
    <screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
    <rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
    <size x="0" y="0" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
    <%
      var str = vXML.low+"℃~"+vXML.hi+"℃";
        for(var a=0;a<str.length;a++){
        if(str.charAt(a)!="/"){%>
    <ScreenOverlay>
    <name><%=a%></name>
    <drawOrder>81</drawOrder>
    <Icon>
    <href><![CDATA[<%=ServerURL%>/img/<%=str.charAt(a)%>.png]]></href>
    </Icon>
    <overlayXY x="-<%=a*14+30%>" y="160" xunits="pixels" yunits="pixels"/>
    <screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
    <rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
    <size x="0" y="0" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
        <%}}
        }%>
	</Folder>
	<%
	//白天
	}else{
	%>
	<Folder>
        <name><%=XMLtime(i-1)%>-白天</name>
		<TimeSpan>
			<begin><%=XMLtime(i-1)%>T07:00:01Z</begin>
			<end><%=XMLtime(i-1)%>T19:00:00Z</end>
		</TimeSpan>
		<%
		var vXML;
		if(curren){
		for(var n=0;n<XMLs.length;n++){
		vXML = new XMLparse(n,(i+1)/2-1,0);
		%>
        <Placemark>
        <name><%=vXML.dnam%>(<%=vXML.low%>℃~<%=vXML.hi%>℃)</name>
		<Snippet maxLines="2"/>
        <description><![CDATA[风速：<%=vXML.winds%>千米/每小时]]></description>
        <Style>
			<IconStyle>
				<scale>1.2</scale>
				<Icon>
					<href><%=ServerURL%>/img/icon/<%=vXML.icon%>s.png</href>
				</Icon>
			</IconStyle>
            <BalloonStyle>
				<color>FFCC99</color>
				<text><![CDATA[<img src="<%=ServerURL%>/img/logo/logo-ge.png" width="121" height="30" border="0" /><br /><b><font face="宋体" size="5" color="#000000">$[name]</font></b><br /><font face="宋体" size="4" color="#000000">$[description]</font><br /><font face="Verdana" size="3">Design©<a href="http://www.dnxh.cn">www.dnxh.cn</a> || Date©<a href="http://www.weather.com/?prod=xoap&amp;par=1017780104">Weather.com</a><sup>®</sup> || Icon©<a href="http://www.yahoo.com">Yahoo</a></font>]]></text>
			</BalloonStyle>
		</Style>
			<Point>
				<coordinates><%=vXML.lon%>,<%=vXML.lat%></coordinates>
			</Point>
        </Placemark>
        <%}}else{
        vXML = new XMLparse(0,(i+1)/2-1,0);
        %>
    <ScreenOverlay>
    <name><%=vXML.dnam%>(<%=vXML.low%>℃~<%=vXML.hi%>℃)</name>
    <drawOrder>80</drawOrder>
    <description><![CDATA[风速：<%=vXML.winds%>千米/每小时]]></description>
    <Icon>
      <href><![CDATA[<%=ServerURL%>/img/icon/<%=vXML.icon%>d.png]]></href>
    </Icon>
    <overlayXY x="0" y="180" xunits="fraction" yunits="pixels"/>
    <screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
    <rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
    <size x="0" y="0" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
        <%
        var str = vXML.low+"℃~"+vXML.hi+"℃";
        for(var a=0;a<str.length;a++){
        if(str.charAt(a)!="/"){%>
    <ScreenOverlay>
    <name><%=a%></name>
    <drawOrder>81</drawOrder>
    <Icon>
    <href><![CDATA[<%=ServerURL%>/img/<%=str.charAt(a)%>.png]]></href>
    </Icon>
    <overlayXY x="-<%=a*14+30%>" y="160" xunits="pixels" yunits="pixels"/>
    <screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
    <rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
    <size x="0" y="0" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
        <%}}
        }%>
	</Folder>
<%
   }
  }
}
XMLs='';
%>
</Document>
</kml>